<template>
  <div class="img_item" @click="toPath">

    <div class="img">
      <img :src="data.path || DEFAULT_IMG" alt="" />
    </div>

    <div class="cont">
      <p class="title">{{ data.title }}</p>
      <p class="des">
        {{ data.desc }}
      </p>
      <p class="tag">
        <el-tag type="success">{{ data.tag }}</el-tag>
      </p>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router';
const props = defineProps({
  data: {
    type: Object,
    default: () => {},
  },
});

import DEFAULT_IMG from '@/assets/banner.jpg';

const router = useRouter();

const toPath = () => {
  router.push('/imageDetail?id=' + props.data?.id);
};
</script>

<style scoped>
.img_item {
  padding: 2rem; 
  border-bottom: 1px solid var(--borderColor);
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
}

.img {
  width: 40vw;
  height: 35vh; 
  overflow: hidden;
  margin-right: 2rem; 
}

.img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: all 0.3s;
}

img:hover {
  transform: scale(1.1); 
}

.cont {
  padding-left: 2rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.title {
  font-size: 1.2rem;
  color: var(--textColor);
  cursor: default;
}

.des {
  font-size: 1rem;
  line-height: 1.5rem;
  color: var(--infoColor);
  overflow: hidden; 
  text-overflow: ellipsis;
  max-height: 7.5rem; 
}

@media (max-width: 768px) {
  .img {
    width: 100%; 
    height: auto; 
    margin-bottom: 1rem; 
  }

  .cont {
    padding-left: 0;
  }
}
</style>